#include <iostream>
#include <string>
#include <vector>

// str为要分割的字符串，sep为分隔符， result为分割后字符串存储的地方，返回给用户
int Split(const std::string &str, const std::string &sep, std::vector<std::string> &result)
{
    // idx为开始查找的位置，pos为查找后目标位置
    size_t idx = 0, pos = 0;
    while(idx < str.size())
    {
        pos = str.find(sep, idx);
        if(pos == std::string::npos)
        {
                result.push_back(str.substr(idx));
            return result.size();
        }
        if(pos == idx)
        {
            idx = pos + sep.size();
            continue;
        }
        result.push_back(str.substr(idx, pos - idx));
        idx = pos + sep.size();
    }
    return result.size();
}


int main()
{
    std::string str = "name....#.ca.12...a";
    std::vector<std::string> vs;
    int n = Split(str, ".", vs);
    for(auto str : vs)
    {
        std::cout << str << std::endl;
    }
    return 0;
}